package com.pcbly.web.components.utils.jfreechart;

import java.awt.Color;
import java.awt.Font;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart; 
import org.jfree.chart.StandardChartTheme;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.time.Year;
import org.jfree.data.xy.XYDataset;

public class TimeLineChart  extends AbstractChartFont {
	/**
	 * 构造数据集
	 * 
	 * @return
	 */
	public  XYDataset getDataSet() {
		String tag = "地区";
		TimeSeries timeSer = new TimeSeries(tag, Year.class);
		timeSer.add(new Year(2000), 1000);
		timeSer.add(new Year(2001), 1300);
		timeSer.add(new Year(2002), 1700);
		timeSer.add(new Year(2003), 1900);
		timeSer.add(new Year(2004), 1400);
		timeSer.add(new Year(2005), 2000);
		timeSer.add(new Year(2006), 2700);
		timeSer.add(new Year(2007), 1800);
		timeSer.add(new Year(2008), 2300);
		timeSer.add(new Year(2009), 1900);

		TimeSeriesCollection timeSerCollection = new TimeSeriesCollection();
		timeSerCollection.addSeries(timeSer);
		return timeSerCollection;
	}
	/**
	 * 根据数据集创建图表对象
	 * 
	 * @param categoryDataset
	 * @return
	 */
	public  JFreeChart createJFreeChart(XYDataset xyDataset) {
		StandardChartTheme standardChartTheme = new StandardChartTheme("name");
		standardChartTheme.setLargeFont(new Font("宋体",Font.BOLD, 10));//可以改变轴向的字体
		standardChartTheme.setRegularFont(new Font("宋体",Font.BOLD, 15));//可以改变图例的字体
		standardChartTheme.setExtraLargeFont(new Font("宋体",Font.BOLD, 24));//可以改变图标的标题字体
		ChartFactory.setChartTheme(standardChartTheme);
		JFreeChart chart = ChartFactory.createTimeSeriesChart(
				"××地区2000年-2009年年降水量曲线图", "年份", "降水量(mm)", xyDataset, true,
				true, false); 
		chart.setBackgroundPaint(Color.WHITE);
		return chart;
	}
	public JFreeChart index(){
		XYDataset dataset=getDataSet();
		return createJFreeChart(dataset); 
	}
}
